package com.kob.redis.service.impl;

import com.kob.redis.result.R;
import com.kob.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class RedisServiceImpl implements RedisService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public R getKey(String key) {
        if (ObjectUtils.isEmpty(key)){
            return R.Failed();
        }
        try{
            Object o = redisTemplate.opsForValue().get(key);
            if (ObjectUtils.isEmpty(o)){
                return R.Failed("结果为空");
            }
            return R.Success(o.toString());
        }catch (Exception e){
            e.printStackTrace();
            return R.Failed("查询异常");
        }
    }

    @Override
    public R saveKey(String key, String value) {
        return null;
    }

    @Override
    public R removeKey(String key) {
        return null;
    }

    @Override
    public R updateValue(String key, String value) {
        return null;
    }
}
